package com.cr.front.brand.service.impl;


import com.cr.front.brand.mapper.BrandMapper;
import com.cr.front.brand.pojo.vo.BrandVO;
import com.cr.front.brand.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    private BrandMapper brandMapper;
    @Override
    public List<BrandVO> selectHot() {
        return brandMapper.selectHot();
    }

    @Override
    public List<BrandVO> selectAll() {
        return brandMapper.selectAll();
    }

    @Override
    public Map<Character, List<BrandVO>> selectLetterBrandList() {
        List<BrandVO> list = brandMapper.selectBrandVOList();
        Map<Character,List<BrandVO>> map = new LinkedHashMap<>();
        for (BrandVO vo : list) {
            if (vo.getPinyin() == null || vo.getPinyin().isEmpty()) {
                continue;
            }
            char first = vo.getPinyin().toUpperCase().charAt(0);
            if (map.containsKey(first)) {
                map.get(first).add(vo);
            } else {
                List<BrandVO> subList = new ArrayList<>();
                subList.add(vo);
                map.put(first, subList);
            }
        }
        return map;
    }
}
